package com.taotao.manage.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.taotao.manage.pojo.ItemCat;
import com.taotao.manage.service.ItemCatService;

@Controller
@RequestMapping("item/cat")
public class ItemCatController {
	@Autowired
	ItemCatService itemCatService;
	
	/*
	 * 查询商品类目
	 * 同步还是异步:异步
	 * 参数:父类目id, 必须, 默认值0
	 * 返回值:list<ItemCat>
	 * 
	 * */
	@RequestMapping(method = RequestMethod.GET)
	public ResponseEntity<List<ItemCat>> queryItemCatByParentId(@RequestParam(required=true,value="id",defaultValue="0") Long id){
		try {
			ItemCat record = new ItemCat();
			record.setParentId(id);
			record.setStatus(1);
			List<ItemCat> list = itemCatService.queryByRecord(record);
			if(list!=null){
				return ResponseEntity.ok(list);
			}else{
				return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
			}
		} catch (Exception e) {
			e.printStackTrace();
			return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
		}
	}
}




